home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 8 / hack.lev.c < prev    next >
C/C++ Source or Header  |  1994-01-27  |  3KB  |  116 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.lev.c version 1.0.1 - somewhat more careful monster regeneration */
  3.  
  4. #include "hack.h"
  5. #include <signal.h>
  6. #include <stdio.h>
  7. extern struct monst *restmonchn();
  8. extern struct obj *restobjchn();
  9. extern struct obj *billobjs;
  10. extern char *itoa();
  11.  
  12. extern char nul[];
  13. #ifndef NOWORM
  14. #include   "def.wseg.h"
  15.  
  16. extern struct wseg *wsegs[32], *wheads[32];
  17. extern long wgrowtime[32];
  18. #endif NOWORM
  19.  
  20. getlev(fd)
  21. {
  22.    register struct gen *gtmp;
  23. #ifndef NOWORM
  24.    register struct wseg *wtmp;
  25. #endif NOWORM
  26.    register int tmp;
  27.    long omoves;
  28.  
  29.    if(fd<0 || read(fd, (char *) levl, sizeof(levl)) != sizeof(levl))
  30.       return(1);
  31.    fgold = 0;
  32.    ftrap = 0;
  33.    mread(fd, (char *)&omoves, sizeof(omoves));   /* 0 from MKLEV */
  34.    mread(fd, (char *)&xupstair, sizeof(xupstair));
  35.    mread(fd, (char *)&yupstair, sizeof(yupstair));
  36.    mread(fd, (char *)&xdnstair, sizeof(xdnstair));
  37.    mread(fd, (char *)&ydnstair, sizeof(ydnstair));
  38.  
  39.    fmon = restmonchn(fd);
  40.    if(omoves) {
  41.     /* regenerate animals while on another level */
  42.     long tmoves = (moves > omoves) ? moves-omoves : 0;
  43.     register struct monst *mtmp, *mtmp2;
  44.     extern char genocided[];
  45.     long newhp;
  46.  
  47.        for(mtmp = fmon; mtmp; mtmp = mtmp2) {
  48.       mtmp2 = mtmp->nmon;
  49.       if(index(genocided, mtmp->data->mlet)) {
  50.          mondead(mtmp);
  51.          continue;
  52.         }
  53.         newhp = mtmp->mhp +
  54.             (index("ViT", mtmp->data->mlet) ? tmoves : tmoves/20);
  55.         if(newhp > mtmp->orig_hp)
  56.             mtmp->mhp = mtmp->orig_hp;
  57.         else
  58.             mtmp->mhp = newhp;
  59.        }
  60.    }
  61.  
  62.    setshk();
  63.    setgd();
  64.    gtmp = newgen();
  65.    mread(fd, (char *)gtmp, sizeof(struct gen));
  66.    while(gtmp->gx) {
  67.       gtmp->ngen = fgold;
  68.       fgold = gtmp;
  69.       gtmp = newgen();
  70.       mread(fd, (char *)gtmp, sizeof(struct gen));
  71.    }
  72.    mread(fd, (char *)gtmp, sizeof(struct gen));
  73.    while(gtmp->gx) {
  74.       gtmp->ngen = ftrap;
  75.       ftrap = gtmp;
  76.       gtmp = newgen();
  77.       mread(fd, (char *)gtmp, sizeof(struct gen));
  78.    }
  79.    free((char *) gtmp);
  80.    fobj = restobjchn(fd);
  81.    billobjs = restobjchn(fd);
  82.    rest_engravings(fd);
  83. #ifndef QUEST
  84.    mread(fd, (char *)rooms, sizeof(rooms));
  85.    mread(fd, (char *)doors, sizeof(doors));
  86. #endif QUEST
  87.    if(!omoves) return(0);   /* from MKLEV */
  88. #ifndef NOWORM
  89.    mread(fd, (char *)wsegs, sizeof(wsegs));
  90.    for(tmp = 1; tmp < 32; tmp++) if(wsegs[tmp]){
  91.       wheads[tmp] = wsegs[tmp] = wtmp = newseg();
  92.       while(1) {
  93.          mread(fd, (char *)wtmp, sizeof(struct wseg));
  94.          if(!wtmp->nseg) break;
  95.          wheads[tmp]->nseg = wtmp = newseg();
  96.          wheads[tmp] = wtmp;
  97.       }
  98.    }
  99.    mread(fd, (char *)wgrowtime, sizeof(wgrowtime));
  100. #endif NOWORM
  101.    return(0);
  102. }
  103.  
  104. mread(fd, buf, len)
  105. register int fd;
  106. register char *buf;
  107. register unsigned len;
  108. {
  109. register int rlen;
  110.    rlen = read(fd, buf, (int) len);
  111.    if(rlen != len){
  112.       pline("Read %d instead of %d bytes\n", rlen, len);
  113.       panic("Cannot read %d bytes from file #%d\n", len, fd);
  114.    }
  115. }
  116.